$(function(){

	//homologacion
	if($("#homologacion_opciones_seleccionar").attr('checked'))
		$("#agregar").hide();
	else
		$("#seleccionar").hide();

	$("#homologacion_opciones_seleccionar").change(function() {	
		$("#seleccionar").toggle('blind');
		$("#agregar").toggle('blind');
	});

	$("#homologacion_opciones_agregar").change(function() {
		$("#seleccionar").toggle('blind');
		$("#agregar").toggle('blind');
	});

});

function iniciaTablaForm(tableSelector, addSelector, delSelector, url) {
	var index = $(tableSelector + ' tbody tr').length;
	
	$(addSelector).click(function() {
		$.ajax({
			url: url,
			data: { index: index++ },
			success: function(data) {
				$(tableSelector + ' tbody').append(data);
			}
		});
		
		return false;
	 });
	 
	 $(tableSelector).on('click', delSelector,function() {
		if (confirm('¿Desea eliminar el registro seleccionado?'))
			$(this).parents('tr').remove();

		return false;
	 });
}

function iniciaTinyMCE(inputSelector) {
	tinyMCE.init({
		language: 'es',
		mode: 'exact',
		elements: inputSelector,
		theme: 'advanced',
		skin: 'o2k7',
		skin_variant: 'silver',
		width: '100%',
		height: '400px',
		theme_advanced_toolbar_location: 'top',
		theme_advanced_toolbar_align: 'left',
		theme_advanced_statusbar_location: 'bottom',
		theme_advanced_resizing: true,
		plugins : 'autolink,lists,pagebreak,style,layer,table,save,advhr,advimage,advlink,iespell,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,inlinepopups,autosave',
			theme_advanced_buttons1 : 'bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,styleselect,formatselect,fontselect,fontsizeselect',
			theme_advanced_buttons2 : 'cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,|,insertdate,inserttime,preview,|,forecolor,backcolor',
			theme_advanced_buttons3 : 'tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,iespell,advhr,|,print,|,fullscreen',
			theme_advanced_buttons4 : 'insertlayer,moveforward,movebackward,absolute,|,visualchars,nonbreaking,pagebreak',
	});
}
